const VIEWER = "viewer"
const EDITOR = "editor"
const CREATOR = "creator"

export const spaceUserRoles = [
    {role: VIEWER, label: '预览者', value: 0},
    {role: EDITOR, label: '编辑者', value: 1},
    {role: CREATOR, label: '创建者', value: 2},
]

export const isSpaceCreator = (role: string | null) => {
    if (role == null) {
        return false
    }
    return role === CREATOR
}

export const isSpaceEditor = (role: string | null) => {
    if (role == null) {
        return false
    }
    return role === EDITOR
}


export const isSpaceView = (role: string | null) => {
    if (role == null) {
        return false
    }
    return role === EDITOR
}

export const getSpaceUserRoleName = (role: string | null) => {
    if (role == null) {
        return "未知"
    }

    for (let spaceUserRole of spaceUserRoles) {
        if (spaceUserRole.role == role) {
            return spaceUserRole.label
        }
    }

    return "未知"

}